/*
 * deadend.gui.UIMain
 * Copyright (C) Yang JiaJian 2009 <Yang JiaJian>
 * deadend.gui.UIMain is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * deadend.gui.UIMain is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
 * UIMain.java
 *
 * Created on 2009-3-7, 15:55:34
 */

package deadend;

import deadend.gui.*;
import deadend.game.*;
/**
 *
 * @author Yang JiaJian
 */
public class UIMain extends javax.swing.JFrame {

    deadend.game.DeadEndGame game;
    /** Creates new form UIMain */
    public UIMain() {
        this.game=new DeadEndGame();
        this.game.intialize();
        initComponents();

        this.deadEndGamePanel1.initGame(game);
        this.deadEndControlPanel1.initGame(game,this.deadEndGamePanel1);
        this.update();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        deadEndGamePanel1 = new deadend.gui.DeadEndGamePanel(this.game);
        jScrollBar1 = new javax.swing.JScrollBar();
        deadEndControlPanel1 = new deadend.gui.DeadEndControlPanel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();

        FormListener formListener = new FormListener();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(566, 729));

        javax.swing.GroupLayout deadEndGamePanel1Layout = new javax.swing.GroupLayout(deadEndGamePanel1);
        deadEndGamePanel1.setLayout(deadEndGamePanel1Layout);
        deadEndGamePanel1Layout.setHorizontalGroup(
            deadEndGamePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 501, Short.MAX_VALUE)
        );
        deadEndGamePanel1Layout.setVerticalGroup(
            deadEndGamePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 501, Short.MAX_VALUE)
        );

        jScrollBar1.setMaximum(1000);
        jScrollBar1.setUnitIncrement(250);
        jScrollBar1.setValue(deadend.game.GameConfigClass.InitRefreshTimeMS);
        jScrollBar1.setValueIsAdjusting(true);
        jScrollBar1.addAdjustmentListener(formListener);

        deadEndControlPanel1.setMinimumSize(new java.awt.Dimension(520, 120));
        deadEndControlPanel1.setPreferredSize(new java.awt.Dimension(520, 120));

        jMenu1.setText("File");
        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");
        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(deadEndGamePanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(deadEndControlPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(deadEndGamePanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(deadEndControlPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(20, Short.MAX_VALUE))
        );

        pack();
    }

    // Code for dispatching events from components to event handlers.

    private class FormListener implements java.awt.event.AdjustmentListener {
        FormListener() {}
        public void adjustmentValueChanged(java.awt.event.AdjustmentEvent evt) {
            if (evt.getSource() == jScrollBar1) {
                UIMain.this.jScrollBar1AdjustmentValueChanged(evt);
            }
        }
    }// </editor-fold>//GEN-END:initComponents

    private void jScrollBar1AdjustmentValueChanged(java.awt.event.AdjustmentEvent evt) {//GEN-FIRST:event_jScrollBar1AdjustmentValueChanged
        this.game.refreshTime=this.jScrollBar1.getValue();
        this.game.ticker.setDelay(this.jScrollBar1.getValue());
    }//GEN-LAST:event_jScrollBar1AdjustmentValueChanged

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new UIMain().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private deadend.gui.DeadEndControlPanel deadEndControlPanel1;
    private deadend.gui.DeadEndGamePanel deadEndGamePanel1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JScrollBar jScrollBar1;
    // End of variables declaration//GEN-END:variables

    /**
     * Update the control panel
     */
    public void update(){
        this.deadEndControlPanel1.update();
        this.repaint();
    }

}
